﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSGui.Classes;
using System.Web.Security;
using POSGui.Classes.BusinessLogic;

namespace POSGui.Presentacion
{
    public partial class Configuracion : System.Web.UI.Page
    {
        private DropDownList _comboReference;
        private int[] _storeIds;

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        protected void btnGuardar_Click(Object sender, EventArgs e)
        {
            ClientManager.GetInstance().DefaultStore = _storeIds[_comboReference.SelectedIndex];
        }

        protected void LoadStores(object sender, EventArgs e)
        {
            _comboReference = (DropDownList)sender;
            try
            {
                WebServiceAgent userAgent = (WebServiceAgent)Session[Constants.USER_WEB_SERVICE_CONN];
                ERPSIA.StoreRoom[] _storeList = userAgent.GetStoreRooms();
                _storeIds = new int[_storeList.Length];

                for (int i = 0; i < _storeList.Length; i++)
                {
                    _comboReference.Items.Add(_storeList[i].Name);
                    _storeIds[i] = _storeList[i].Id;
                }
            }
            catch (Exception)
            {
                FailureText.Text = Constants.SYSTEM_NOT_AVAILABLE;
            }
        }

        protected void LoadCurrencies(object sender, EventArgs e)
        {
            _comboReference = (DropDownList)sender;
            try
            {
                WebServiceAgent userAgent = (WebServiceAgent)Session[Constants.USER_WEB_SERVICE_CONN];
                ERPSIA.Currency[] _currenciesList = userAgent.GetCurrencies();

                for (int i = 0; i < _currenciesList.Length; i++)
                {
                    _comboReference.Items.Add(_currenciesList[i].Name);
                }
            }
            catch (Exception)
            {
                FailureText.Text = Constants.SYSTEM_NOT_AVAILABLE;
            }
        }

        
    }
}